package com.openbravo.pos.forms;

import java.net.MalformedURLException;
import java.util.Date;
import java.util.List;

import com.openbravo.data.loader.TableDBSentenceBuilder;
import net.xeoh.plugins.base.PluginManager;
import net.xeoh.plugins.base.impl.PluginManagerFactory;
import e.odbo.data.dao.I_DataLogic;
import cn.ekuma.epos.datalogic.define.DataLogicERP;
import cn.ekuma.epos.datalogic.hessian.HessianDataLogicHelper;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.I_Session;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppConfig;
import com.openbravo.pos.base.AppViewConnection;

public class StartSync {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/**
		AppConfig config = new AppConfig(args);
        config.load();
        
        I_Session  session = null;
        PluginManager pmf = PluginManagerFactory.createPluginManager();
        
        try {
				HessianDataLogicHelper.init(config.getProperty(AppConfig.ERP_URL));
			} catch (MalformedURLException e) {
				  e.printStackTrace();
				  System.exit(0);
			}
           
            try {
                session = new AppViewConnection().createSession(config);
            } catch (BasicException e) {
                e.printStackTrace();
                System.exit(0);
            }
            
            final DataLogicERP dataLogicSrc=new DataLogicERP(session,null,null,null,new TableDBSentenceBuilder(session,));
            
            final I_DataLogic dataLogicDest= HessianDataLogicHelper.getDLERP();
            
            SetupSyncProperty dialog=new SetupSyncProperty(){
				@Override
				public void doJob() {
					Date startdate;
					try {
						startdate = (Date) Formats.TIMESTAMP.parseValue(jTxtStartDate.getText());
					} catch (BasicException e1) {
						startdate=null;
						e1.printStackTrace();
					}
					Date enddate;
					try {
						enddate = (Date) Formats.TIMESTAMP.parseValue(jTxtEndDate.getText());
					} catch (BasicException e1) {
						enddate=null;
						e1.printStackTrace();
					}
					SyncManager syncManager;
					List<Class> sClasses;
					boolean isClient=clientModel.isSelected();
					if(isClient){
						  syncManager=new SyncManager(dataLogicDest,dataLogicSrc);
						  sClasses=dataLogicSrc.getSyncClient();
					}else{
						 syncManager=new SyncManager(dataLogicSrc,dataLogicDest);
						 sClasses=dataLogicSrc.getSyncService();
					}
					try {
						 for(Class c:sClasses){
							jMemo.append("----->开始 "+c.getName()+"\n");
							long begintime = System.currentTimeMillis();
							syncManager.sync(c, startdate, enddate);
							long endtime = System.currentTimeMillis();
							jMemo.append("-->用时： "+(endtime-begintime)+"\n");
						 }
						 jMemo.append("执行完毕。");
						} catch (BasicException e) {
							e.printStackTrace();
							jMemo.append(e.getMessage()+"\n");
						}
				}
            };
            dialog.setVisible(true);**/
	}

}
